//
//  TokenPlugin.swift
//  777Proj
//
//  Created by 陈宇 on 2017/5/15.
//  Copyright © 2017年 🐜. All rights reserved.
//

import Moya
import Result

final class TokenPlugin: PluginType {
    
    func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
        guard let token = UIApplication.token, let target = target as? RestFullAPI, target.requiredToken else {
            return request
        }
        
        var req: URLRequest = URLRequest(url: request.url!, cachePolicy: request.cachePolicy, timeoutInterval: request.timeoutInterval)
        req.addValue(token, forHTTPHeaderField: "token")
        return req
    }
    
}
